/*
 * Created on May 28, 2010 - 2:17:40 PM
 */
package nl.liacs.jmseq.verify.failurehandler;

import nl.liacs.jmseq.annotation.SequencedMethod;
import nl.liacs.jmseq.execution.Execution;

/**
 * 
 * 
 * @author Behrooz Nobakht [behrooz dot nobakht at gmail dot com]
 */
public class SequentialMetadataVerificationFailureHandler implements VerificationFailureHandler {

	public void handleVerificationFailure(Execution execution, SequencedMethod annotation) {
		Class<?> handlerClass = annotation.verificationFailureHandler();
		if (null == handlerClass) {
			System.out.println("No handler class for verification failure is specified.");
			return;
		}
		if (!VerificationFailureHandler.class.isAssignableFrom(handlerClass)) {
			System.err.println("No compatible " + VerificationFailureHandler.class + " handler is provided. " +
					"Skipping the failure handling of " + execution);
			return;
		}
		try {
			VerificationFailureHandler handler = (VerificationFailureHandler) handlerClass.newInstance();
			handler.handleFailedExecution(execution);
		} catch (InstantiationException e) {
			System.err.println("Failed to instantiate verification handler instance from: " + handlerClass);
		} catch (IllegalAccessException e) {
			System.err.println("Failed to instantiate verification handler instance from: " + handlerClass);
		}
	}

	@Override
	public final void handleFailedExecution(Execution<?> execution) {
	}

}
